package com.lft.com.oilgas.service.impl;

import com.lft.com.oilgas.entity.IdCard;
import com.lft.com.oilgas.entity.Merchant;
import com.lft.com.oilgas.mapper.IdCardMapper;
import com.lft.com.oilgas.mapper.MerchantMapper;
import com.lft.com.oilgas.service.IIdCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tyqw
 * @since 2024-09-10
 */
@Service
public class IdCardServiceImpl implements IIdCardService {
    @Autowired
    private IdCardMapper idCardMapper;
    @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public void InsertOrUpdate(IdCard idCard) {
        System.out.println(idCard);
        if (idCard.getId() != null ) {
            idCardMapper.updateById(idCard);
        } else {
            idCardMapper.insert(idCard);
            System.out.println(idCard.getMerchantid());
            if (idCard.getMerchantid() != 0) {
                Merchant merchant = merchantMapper.selectById(idCard.getMerchantid());
                if (idCard.getSanhulei() == 2) {
                    merchant.setLegalPerson(idCard.getId());
                } else {
                    merchant.setCardId(idCard.getId());
                }
                merchantMapper.updateById(merchant);
            }
        }
    }

    @Override
    public IdCard selectOne(Integer id) {
        return  idCardMapper.selectById(id);
    }
}
